import Vue from 'vue'
import axios from "axios"; //npm install axios@0.27.1
import { UniAdapter } from "uniapp-axios-adapter";
import {baseUrl} from "../js/config.js"
// 每次请求都创建一个新的实例
const http = axios.create({
  baseURL: baseUrl + "/app-api", //
  timeout: 5000,
  adapter: UniAdapter, // 指定适配器
});
let whitelist = ['/login']
//对请求进行拦截
http.interceptors.request.use(config => {
		let token = uni.getStorageSync("login-token")
        if(token != ""){
            config.headers['Authorization']='Bearer' + token //jwt认证的令牌
        }
        return config
    },error => {
        console.log(error)
		uni.redirectTo({
			url:"/pages/login/login"
		})
        Promise.reject(error)
})  

http.interceptors.response.use(response=>{
        let res = response.data
        console.log('------------------response-----------------\n',res)
        return res
})

export default http